import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1 
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed 
 * 
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'IM即时通讯', icon: 'dashboard',auth_code:"/statistics" }
    }]
  },

  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: '系统管理', icon: 'el-icon-s-help',auth_code:"STYLETEM" },
    children: [
      {
        path: 'table',
        name: '角色(基础权限)', 
        component: () => import('@/views/table/index'),
        meta: { title: '角色(基础权限)', icon: 'table',auth_code:"auth/roleList" }
      },
      {
        path: 'tree',
        name: '菜单管理',
        component: () => import('@/views/tree/index'),
        meta: { title: '菜单管理', icon: 'tree',auth_code:"auth/menuList" }
      },
      {
        path: 'Serverconfiguration',
        name: '服务器配置',
        component: () => import('@/views/Serverconfiguration/index'),
        meta: { title: '服务器配置', icon: 'tree',auth_code:"config/setServer" }
      },
      {
        path: 'managementmodule',
        name: '客户端模块管理',
        component: () => import('@/views/managementmodule/index'),
        meta: { title: '客户端模块管理', icon: 'tree',auth_code:"config/setClient" }
      }
    ]
  },
  {
    path: '/usermanagement',
    component: Layout,
    redirect: '/usermanagement/userlist',
    name: '用户管理',
    meta: { title: '用户管理', icon: 'el-icon-s-help',auth_code:"Usermanagement" },
    children: [
      {
        path: 'userlist',
        component: () => import('@/views/usermanagement/userlist/list.vue'),
        name: '用户列表',
        meta: { title: '用户列表',auth_code:"user/userList" }
      },
      // {
      //   path: 'userauthentication',
      //   component: () => import('@/views/usermanagement/userauthentication'),
      //   name: '个人认证',
      //   meta: { title: '个人认证' } 
      // },
      // {
      //   path: 'enterprise',
      //   component: () => import('@/views/usermanagement/enterprise/certification.vue'),
      //   name: '企业认证',
      //   meta: { title: '企业认证' } 
      // }
    ]
  },
  {
    path: '/rolemanagement',
    component: Layout,
    redirect: '/rolemanagement/administrators',
    name: '角色管理',
    meta: { title: '角色管理', icon: 'el-icon-s-help',auth_code:"Rolemanagement" }, 
    children: [
      {
        path: 'administrators',
        component: () => import('@/views/rolemanagement/administrators/aDministrators.vue'),
        name: '管理员',
        meta: { title: '管理员',auth_code:"auth/adminList"}
      },
      // {
      //   path: 'customerservice',
      //   component: () => import('@/views/rolemanagement/customerservice/customerService.vue'),
      //   name: '客服',
      //   meta: { title: '客服' }
      // },
      // {
      //   path: 'finance',
      //   component: () => import('@/views/rolemanagement/finance/Finance.vue'),
      //   name: '财务',
      //   meta: { title: '财务' }
      // }
    ]
  },
  {
    path: '/groupmanagement',
    component: Layout,
    children: [
      {
        path: 'index',
        name: '群组管理',
        component: () => import('@/views/groupmanagement/index'),
        meta: { title: '群组管理', icon: 'form',auth_code:"groupmanagement" }
      }
    ]
  },
  {
    path: '/wechatmoments',
    component: Layout,
    children: [
      {
        path: 'wechatMoments',
        name: '朋友圈',
        component: () => import('@/views/wechatmoments/wechatMoments'),
        meta: { title: '朋友圈', icon: 'form',auth_code:"group/groupList" }
      }
    ]
  },
  {
    path: '/interfacelog',
    component: Layout,
    children: [
      {
        path: 'interFacelog',
        name: '接口日志',
        component: () => import('@/views/interfacelog/interFacelog'),
        meta: { title: '接口日志', icon: 'form',auth_code:"opLogs/logList" }
      }
    ]
  },
  {
    path: '/complaintsreport',
    component: Layout,
    children: [
      {
        path: 'complaintsreport',
        name: '投诉举报',
        component: () => import('@/views/Complaintsreport/complaintsreport'),
        meta: { title: '投诉举报', icon: 'form',auth_code:"feedback/reportList" }
      }
    ]
  },
  {
    path: '/Dynamicmanagement',
    component: Layout,
    children: [
      {
        path: 'dynamicmanagement',
        name: '意见反馈',
        component: () => import('@/views/Dynamicmanagement/dynamicmanagement'),
        meta: { title: '意见反馈', icon: 'form',auth_code:"feedback/list" }
      }
    ]
  },
  {
    path: '/interfaceCall',
    component: Layout,
    children: [
      {
        path: 'interfacecall',
        name: '第三方接入调用',
        component: () => import('@/views/interfaceCall/interfacecall'),
        meta: { title: '第三方接入调用', icon: 'form',auth_code:"config/thirdPartySwitchList" }
      }
    ]
  },  
  
  
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router